package com.emperor.controller.userservice;


import com.emperor.dto.PartnerSaveDto;
import com.emperor.dto.UserPartnerDto;
import com.emperor.result.Result;
import com.emperor.service.PartnerService;
import com.emperor.vo.PartnerIdVo;
import com.emperor.vo.SkuClassPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "合作商管理")
@RestController
@RequestMapping("/user-service/partner")
public class PartnerController {
    @Autowired
    private PartnerService partnerService;

    /**
     * 新增合作商
     *
     * @param dto
     * @return
     */
    @ApiOperation("新增合作商")
    @PostMapping
    public Result save(@RequestBody PartnerSaveDto dto) {
        partnerService.save(dto);
        return Result.success();
    }

    /**
     * 修改密码
     *
     * @param id
     * @return
     */
    @ApiOperation("修改密码")
    @PatchMapping("/updatePwd/{id}")
    public Result updatePwd(@PathVariable Integer id, @RequestBody UserPartnerDto userPartnerDto) {
        partnerService.updatePwd(id, userPartnerDto);
        return Result.success();
    }

    @ApiOperation("合作商搜索")
    @GetMapping("/search")
    public Result<SkuClassPageVo> findAll(Integer pageIndex, Integer pageSize, String name) {
        SkuClassPageVo vo = partnerService.findAll(pageIndex, pageSize, name);
        return Result.success(vo);
    }

    @ApiOperation("获取合作商详情")
    @GetMapping("/{id}")
    public Result<PartnerIdVo> getPartnerById(@PathVariable Integer id) {
        PartnerIdVo vo = partnerService.getPartnerById(id);
        return Result.success(vo);
    }

    @ApiOperation("修改合作商")
    @PutMapping("/{id}")
    public Result updatePartner(@PathVariable Integer id, @RequestBody PartnerSaveDto dto) {

        partnerService.updatePartner(id, dto);
        return Result.success();
    }

    @ApiOperation("删除合作商")
    @DeleteMapping("/{id}")
    public Result deletePartner(@PathVariable Integer id) {
        partnerService.deletePartner(id);
        return Result.success();
    }

    @ApiOperation("合作商数量")
    @GetMapping("/count")
    public Integer count() {
        return partnerService.count();
    }
}
